import React, { useState } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, Button } from 'react-native';
import AgreementScreen from './account/agreement';

const SecondScreen = ({ navigation }: any) => {
  const [showAgreement, setShowAgreement] = useState(false); // 控制弹窗显示

  const handleAgreementResult = (agreed: any) => {
    setShowAgreement(false); // 关闭协议弹窗

    if (agreed) {
      console.log('用户已同意协议');
    } else {
      console.log('用户拒绝协议');
    }
  };

  return (
    <View style={styles.container}>
      <Button
        title="Go to Home"
        onPress={() => navigation.navigate('MainRouter')}
      />
      {/* 触发弹窗的按钮 */}
      <TouchableOpacity
        style={styles.button}
        onPress={() => setShowAgreement(true)}
      >
        <Text style={styles.buttonText}>查看协议</Text>
      </TouchableOpacity>

      {/* 协议弹窗组件 */}
      <AgreementScreen
        visible={showAgreement}
        onClose={handleAgreementResult}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
    padding: 20,
  },
  title: {
    fontSize: 22,
    fontWeight: 'bold',
    marginBottom: 10,
  },
  description: {
    fontSize: 16,
    color: '#666',
    marginBottom: 30,
    textAlign: 'center',
  },
  button: {
    backgroundColor: '#007AFF',
    paddingHorizontal: 30,
    paddingVertical: 15,
    borderRadius: 8,
  },
  buttonText: {
    color: 'white',
    fontSize: 16,
    fontWeight: '600',
  },
});

export default SecondScreen;
